#-------------------------------------------------------------------------------
# Name:        testProgram
# Purpose:
#
# Author:      Nick
#
# Created:     20/06/2012
# Copyright:   (c) Nick 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------

def main():
    # syntax for a variable assignment
    # var_name = value
    word ="python"
    strlist = list(word)
    lettersTried = "";
    badguesses = 0;
    goodguesses = 0;
    maxbadguesses = 9;
    while(badguesses < maxbadguesses and goodguesses < len(word)):
        print
        print
        print
        printWord(word, lettersTried, strlist)
        print("lettersTried: " + lettersTried + "    # of bad guesses left: " + str(maxbadguesses - badguesses))
        user_input = raw_input("Enter guess: ")
        user_input = user_input.strip()
        user_input = user_input.lower()
        if len(user_input) == 1 and user_input.isalpha():
            if lettersTried.find(user_input) != -1:
                print("You have already tried this letter, please choose another input.")
            else:
                lettersTried = lettersTried + user_input;
                first_index = word.find(user_input)
                if(first_index == -1):
                    badguesses = badguesses + 1
                    print(user_input + " is not in the word.")
                else:
                    occurences = word.count(user_input)
                    goodguesses = goodguesses + occurences
                    print(user_input + " was in the word!")
    print
    print
    print
    if badguesses >= maxbadguesses:
        print("Sorry, you have run out of guesses. ")
        print("The Word was: " + word)
    else:
        print("You've found all the letters! The word was: '" + word + "'")
        print("Congratulations, You Win!")

def printWord(word, lettersTried, strlist):
    fullWord = ""
    for i in range(len(word)):
        if lettersTried.find(strlist[i]) != -1:
            fullWord = fullWord + (strlist[i] + " ")
        else:
            fullWord = fullWord + "__ "
    print(fullWord)

if __name__ == '__main__':
    main()